###########################################
#REPLICATION FILE FOR VOX POPULI, VOX DEI?
#by ADAM RAMEY
#SECTION 5 (incl. FIGURES 2, 4, and 6)
###########################################

library(ggplot2)

##be sure to change the line below so as to indicate where the data and scripts are
setwd("~/Downloads/Replication Materials/")

hou <- read.csv('House112withVoters-AM.csv')
sen <- read.csv('Senate112withVoters-AM.csv')

##Figure 2
ggsave(ggplot(sen, aes(mccain08,state.voter,label=state)) +
  geom_text() + 
  theme_bw() +
  xlab("McCain 2008 Voteshare") +
  ylab("State Mean Voter"), 
  file="voterideology.pdf",
  height=6, width=8)

##Figure 4
ggsave(ggplot(sen, aes(wnominate,surveypts,label=party)) +
         geom_text() +
         theme_bw() +
         xlab("W-NOMINATE 112th Senate") +
         ylab("Rescaled Aldrich-McKelvey (2010 CCES)"), 
       file="wnom_aldmck_senate_compare.pdf",
       height=6, width=8)


ggsave(ggplot(hou, aes(wnom1,surveypts,label=party)) +
         geom_text() + 
         theme_bw() +
         xlab("W-NOMINATE 112th House") +
         ylab("Rescaled Aldrich-McKelvey (2010 CCES)"), 
       file="wnom_aldmck_house_compare.pdf",
       height=6, width=8)


##Figure 6

ggsave(ggplot(sen, aes(wnominate,linetype=party,fill=party)) +
         geom_density(alpha=0.3) +
         theme_bw() +
         scale_fill_grey(name="\nParty\n") +
         scale_linetype(name="\nParty\n") +
         xlab("W-NOMINATE 112th Senate") +
         ylab("") + 
         scale_x_continuous(limits = c(-1.5,1.5)), 
       file="wnom_senate.pdf",
       height=6, width=8)


ggsave(ggplot(hou, aes(wnom1,linetype=party,fill=party)) +
         geom_density(alpha=0.3) +
         theme_bw() +
         scale_fill_grey(name="\nParty\n") +
         scale_linetype(name="\nParty\n") +
         xlab("W-NOMINATE 112th House") +
         ylab("") +
         scale_x_continuous(limits = c(-1.5, 1.5)), 
       file="wnom_house.pdf",
       height=6, width=8)

ggsave(ggplot(sen, aes(surveypts,linetype=party,fill=party)) +
         geom_density(alpha=0.3) +
         theme_bw() +
         scale_fill_grey(name="\nParty\n") +
         scale_linetype(name="\nParty\n") +
         xlab("Rescaled Aldrich-McKelvey (2010 CCES) Senate") +
         ylab("") +
         scale_x_continuous(limits = c(-1.5, 1.5)), 
       file="aldmck_senate.pdf",
       height=6, width=8)

ggsave(ggplot(hou, aes(surveypts,linetype=party,fill=party)) +
         geom_density(alpha=0.3) +
         theme_bw() +
         scale_fill_grey(name="\nParty\n") +
         scale_linetype(name="\nParty\n") +
         xlab("Rescaled Aldrich-McKelvey (2010 CCES) House") +
         ylab("") +
         scale_x_continuous(limits = c(-1.5, 1.5)), 
       file="aldmck_house.pdf",
       height=6, width=8)

